package com.atguigu.dga.ds.service.impl;

import com.atguigu.dga.ds.bean.TDsTaskInstance;
import com.atguigu.dga.ds.mapper.TDsTaskInstanceMapper;
import com.atguigu.dga.ds.service.TDsTaskInstanceService;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zhangchen
 * @since 2023-11-22
 */
@Service
@DS("ds")
public class TDsTaskInstanceServiceImpl extends ServiceImpl<TDsTaskInstanceMapper, TDsTaskInstance> implements TDsTaskInstanceService {



    public Map<String ,List<TDsTaskInstance>>   getTaskInstanceList(String assessDate){
        List<TDsTaskInstance> taskInstanceList = list(new QueryWrapper<TDsTaskInstance>().eq("date_format(submit_time,'%Y-%m-%d') ", assessDate));

        Map<String ,List<TDsTaskInstance>> taskInstantListMap=new HashMap<>();
        for (TDsTaskInstance tDsTaskInstance : taskInstanceList) {
            // 先检查是否map中已经存在该表的实例
            List<TDsTaskInstance> tDsTaskInstanceList = taskInstantListMap.get(tDsTaskInstance.getName());
            if(tDsTaskInstanceList==null){ //如果不存在 ，则创建一个列表
                tDsTaskInstanceList=new ArrayList<>();
                taskInstantListMap.put(tDsTaskInstance.getName(),tDsTaskInstanceList);
            }
            tDsTaskInstanceList.add(tDsTaskInstance);


        }

        return taskInstantListMap;


    }
}
